home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 102_01.zip / FALLOUT.C < prev    next >
Text File  |  1993-06-03  |  5KB  |  179 lines

  1. /*
  2.     FALLOUT for the H19
  3.  
  4.     This is a logical extension of "flyby.c"
  5.  
  6.     written by Leor Zolman
  7.            July 18, 1980 (I promise to stop playing with the H19
  8.                   and put more work into the v1.4 code
  9.                   optimizer...tomorrow!)
  10. */                  
  11.  
  12. #include "bdscio.h"
  13.  
  14. #define MAXTHINGS 50        /* Maximum # of objects on the screen
  15.                    at once                */
  16. #define INACTIVE  0
  17.  
  18. struct thing {
  19.     char what;    /* Either an Ascii value, or INACTIVE */
  20.     char rev;    /* True if character to be displayed in reverse */
  21.     int rowp;    /* Row position of thing */
  22.     int colp;    /* Column position of thing */
  23.     int speedd;    /* Down speed    */
  24.     int speeda;    /* Across speed (signed to indeciate left or right) */
  25.     char trail;    /* True if displaying trail */
  26.     char zigzag;    /* True if zigzag-ing */
  27.     int zigmag;    /* if zigzag-ing, magnitude of zig and zag */
  28.     int zigpos;    /* Count of how many zigs or zags have been done */
  29. };
  30.  
  31. char halt;        /* goes true when user aborts */
  32.  
  33. main(argc,argv)
  34. char **argv;
  35. {
  36.     struct thing thingtab[MAXTHINGS], *thingie;
  37.     int dspeedt[20], aspeedt[20];    /* Tables of possible speeds    */
  38.     int i,nthings;        /* loop variable, and # of active things */
  39.     char inrev;        /* true if in reverse video */
  40.     char trails;        /* true if displaying all trails */
  41.     char insert_mode;    /* true when insert mode is activated */
  42.     char point_source;    /* true if all things coming from one point */
  43.     int source_point;    /* if point_source true, the horiz pos */
  44.  
  45.     printf("Welcome to H19 Fallout!\r\nWritten by Leor Zolman   7/80");
  46.     initw(dspeedt,"1,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5");
  47.     initw(aspeedt,"0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,7");
  48.     point_source = trails = insert_mode = FALSE;
  49.  
  50. start:    do {
  51.         puts(CLEARS); puts(INTOREV);
  52.         puts("\33y5");  /* cursor on */
  53.         printf(" How many things should I display (1-%d,",
  54.             MAXTHINGS);
  55.         srand1(" or q to quit) ?   \b\b");
  56.         if (!scanf("%d",&nthings)) {
  57.             puts(OUTAREV);
  58.             exit();
  59.          }
  60.     } while (nthings < 1 || nthings > MAXTHINGS);
  61.  
  62.     puts(CLEARS);    puts(OUTAREV);
  63.     halt = inrev = FALSE;
  64.     puts("\33x5");    /* cursor off */
  65.     for (i=0; i<nthings; i++) thingtab[i].what = INACTIVE;
  66.  
  67.     while (!halt) {
  68.  
  69.        if (!(rand() % 99)) {        /* if point source off, make */
  70.         point_source = TRUE;        /* it tough to get it turned */
  71.         source_point = rand() % 79;    /* on...             */
  72.        }
  73.                         /* but easier to turn off    */
  74.        if (point_source && !(rand() % 50)) point_source = FALSE;
  75.  
  76.        if ( trails && !(rand() % 2))
  77.         trails = FALSE;    /* if trails on, lean toward turning off */
  78.  
  79.        else if (!trails && !(rand() % (MAXTHINGS - nthings + 20)))
  80.         trails = TRUE;    /* if trails off, lean to keeping 'em off */
  81.  
  82.        if (!(rand() % ((2 * MAXTHINGS + 5) - nthings * 2 ))) puts(CLEARS);
  83.  
  84.        if (!(rand() % 200)) {
  85.             puts(insert_mode ? "\033O" : "\033@");
  86.             insert_mode = !insert_mode;
  87.         }
  88.  
  89.        for (i=0; i<nthings; i++) {     /* now process each thing */
  90.         thingie = thingtab[i];     /* get pointer to current thing */
  91.  
  92.         if (!thingie -> what) {        /* if it is inactive, create it: */
  93.             thingie -> what = rand() % 96 + ' ';
  94.             thingie -> rev = rand() % 2;
  95.             thingie -> trail = rand() % 30 ? trails : !trails;
  96.  
  97.             thingie -> speedd = dspeedt[rand() % 20];
  98.             thingie -> speeda = aspeedt[rand() % 20] *
  99.                         ((rand() % 2) * 2 - 1);
  100.             if (thingie -> zigzag = !(rand() % 5)) {
  101.                thingie -> zigmag =
  102.                  (rand() % 25 + 2) / abs(thingie -> speeda);
  103.                thingie -> zigpos = thingie -> zigmag / 2;
  104.              }
  105.             thingie -> rowp = 0;
  106.  
  107.             if (!point_source)
  108.                 thingie -> colp = thingie -> zigzag ?
  109.                    thingie->zigzag / 2 + 1 + 
  110.                    rand() % (TWIDTH - thingie -> zigmag) :
  111.                    rand() % TWIDTH;
  112.             else
  113.                 thingie -> colp = source_point;
  114.          }
  115.  
  116.          else {        /* else move it down one iteration */
  117.             if (!thingie -> trail) {  /* if don't need trails, */
  118.                 if (inrev) {      /* erase last position.  */
  119.                     puts(OUTAREV);  /* no reverse video */
  120.                     inrev--;
  121.                  }
  122.                 gotoxy(thingie -> rowp, thingie -> colp,' ');
  123.              }
  124.             if (thingie -> zigzag &&    /* if in zigzag mode */
  125.                ++thingie -> zigpos > thingie -> zigmag) {
  126.                 thingie -> zigpos = 0;    /* then reverse dir */
  127.                 thingie -> speeda = -thingie -> speeda;
  128.                }
  129.             thingie -> rowp += thingie -> speedd;
  130.             thingie -> colp += thingie -> speeda;
  131.             if (  thingie -> rowp > (TLENGTH-1) /* if outa range */
  132.                || thingie -> colp < 0
  133.                || thingie -> colp > (TWIDTH-1) )
  134.               thingie -> what = INACTIVE; /* then turn off */
  135.             else {
  136.                 if (thingie -> rev) {  /* not out of range;  */
  137.                      if (!inrev) {     /* if a reverse char, */
  138.                     puts(INTOREV); /* make sure we're in */
  139.                     inrev = TRUE;  /* reverse video mode */
  140.                       }
  141.                  }
  142.                 else if (inrev) {      /* if not a rev char  */
  143.                     puts(OUTAREV); /* make sure we're in */
  144.                     inrev--;       /* normal video mode  */
  145.                  }
  146.                 gotoxy(thingie -> rowp, thingie -> colp,
  147.                     thingie -> what);
  148.             }
  149.         }
  150.  
  151.        }
  152.     }
  153.     goto start;
  154. }
  155.  
  156. putchar(c)
  157. {
  158.     bios(4,c);
  159. }
  160.  
  161. gotoxy(x,y,c)
  162. {
  163.     char c2;
  164.     if (y <= 78 || x != 23) {
  165.         putchar (ESC);
  166.         putchar ('Y');
  167.         putchar (x + ' ');
  168.         putchar (y + ' ');
  169.         putchar (c);
  170.      }
  171.     if (!bios(2)) return;
  172.     if ((c2 = bios(3)) != 0x13) halt = 1;
  173.     if (c2 == 0x13)
  174.         while (1) {
  175.         while (!bios(2)) rand();
  176.         if (bios(3) == 0x11) break;
  177.          }
  178. }
  179.